package com.sysystem.vo;

import org.apache.commons.lang3.builder.ToStringBuilder;

import com.google.gson.JsonObject;
import com.sysystem.enums.BaseRetCode;

public class BaseResponseVO {

    private String retCode = BaseRetCode.CODE_ERROR_SYS.getRetCode();
    private String retMsg = BaseRetCode.CODE_ERROR_SYS.getRetMsg();
    private Object retData = EmptyRetData.instance;

    public BaseResponseVO(BaseRetCode retCode, Object retData) {
        this(retCode.getRetCode(), retCode.getRetMsg(), retData);

    }

    public BaseResponseVO(String retCode, String retMsg, Object retData) {
        this(retCode, retMsg);
        setRetData(retData);
    }

    public BaseResponseVO(BaseRetCode retCode) {
        this(retCode.getRetCode(), retCode.getRetMsg());
    }

    public BaseResponseVO(String retCode, String retMsg) {
        setRetCode(retCode);
        setRetMsg(retMsg);
    }

    public String getRetCode() {
        return retCode;
    }

    public void setRetCode(String retCode) {
        if (retCode != null) {
            this.retCode = retCode;
        }
    }

    public String getRetMsg() {
        return retMsg;
    }

    public void setRetMsg(String retMsg) {
        if (retMsg != null) {
            this.retMsg = retMsg;
        }
    }

    public Object getRetData() {
        return retData;
    }

    public void setRetData(Object retData) {
        if (retData != null) {
            this.retData = retData;
        } else {
            this.retData = EmptyRetData.instance;
        }
    }

    public String toString() {

        if (BaseRetCode.CODE_SUCCESS.getRetCode().equals(this.retCode)) {
            return ToStringBuilder.reflectionToString(this);
        } else {
            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("retCode", this.getRetCode());
            jsonObject.addProperty("retMsg", this.getRetMsg());
            jsonObject.addProperty("retData", "{}");
            return jsonObject.toString();
        }
    }

}
